

using System;
using System.Collections;
using System.Globalization;

namespace JTC.MiniCommerce.Core.Globalization {
  
  public class CultureComparer : IComparer {

    #region IComparer Members

    /// <summary>
    /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
    /// </summary>
    /// <param name="x">The first object to compare.</param>
    /// <param name="y">The second object to compare.</param>
    /// <returns>
    /// Value Condition Less than zero x is less than y. Zero x equals y. Greater than zero x is greater than y.
    /// </returns>
    /// <exception cref="T:System.ArgumentException">Neither x nor y implements the <see cref="T:System.IComparable"></see> interface.-or- x and y are of different types and neither one can handle comparisons with the other. </exception>
    public int Compare(object x, object y) {
      Validator.ValidateObjectType(x, typeof(CultureInfo));
      Validator.ValidateObjectType(y, typeof(CultureInfo));

      CultureInfo a = x as CultureInfo;
      CultureInfo b = y as CultureInfo;

      return a.DisplayName.CompareTo(b.DisplayName);
    }

    #endregion
    
  }
}
